﻿using System;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using weikebuluo.DAL;
using weikebuluo.Model;
using weikebuluo.Common;

namespace weikebuluo.web.admin.vip
{
    public partial class vipexplain : weikeweixin.web.admin.cs.adminbase
    {
        v_explain_dal explaindal = new v_explain_dal();
        protected v_explain_model explainmodel = new v_explain_model();

        protected void Page_Load(object sender, EventArgs e)
        {
            DataTable dt = explaindal.GetList("user_id=" + user_id).Tables[0];
            if (dt.Rows.Count > 0) {
                explainmodel = explaindal.GetModel(int.Parse(dt.Rows[0]["explain_id"].ToString()));
            }

            switch (Request.Form["action"]) {
                case "bind":
                    bind();
                    break;
            }
        }

        private void bind() {
            DataTable dt = explaindal.GetList("user_id=" + user_id).Tables[0];
            if (dt.Rows.Count > 0)
            {
                explainmodel = explaindal.GetModel(int.Parse(dt.Rows[0]["explain_id"].ToString()));
            }
            explainmodel.explain_use = Request.Form["explain_use"];
            explainmodel.explain_jifen = Request.Form["explain_jifen"];
            explainmodel.explain_address = Request.Form["explain_address"];
            explainmodel.explain_phone = Request.Form["explain_phone"];
            explainmodel.user_id = int.Parse(user_id);
            if (dt.Rows.Count > 0)
            {
                explaindal.Update(explainmodel);
            }
            else {
                explaindal.Add(explainmodel);
            }
            Response.Write("{\"errno\":\"0\",\"tip\":\"设置成功！\",\"url\":\"vipexplain.aspx\",\"error\":\"\"}");
            Response.End();

        }
    }
}